package com.txm.drawPic;
/*
* 敌方坦克
* */
import java.awt.*;

public class EnemyTank extends Tank implements Runnable {

    UsTank enemyTank = null;

    RandomNum shut_randomNum = null;
    RandomNum randomNum = null;

    public EnemyTank(String mark, MyPanel mypanel) {
        super();
        this.setColor(new Color(220, 20, 60));
        this.setColor_alpha(new Color(220, 20, 60, 150));
        this.setMark(mark);
        this.setY(200);
        this.setDirect("3");
        MYPANEL = mypanel;
    }

    @Override
    public void run() {
        randomNum = new RandomNum(new int[]{1, 4}, 1500);
        shut_randomNum = new RandomNum(new int[]{100, 1}, 1000);
        randomNum.start();
        shut_randomNum.start();
        int shut_random_before = 0;
        while (isLive()) {
            if(MYPANEL.gameOver) return;

            if (shut_random_before != shut_randomNum.randomNum && shut_randomNum.randomNum > 50) {
                shut();
                shut_random_before = shut_randomNum.randomNum;
            }
            switch (randomNum.randomNum) {
                case 1:
                    moveUp();
                    break;
                case 2:
                    moveRight();
                    break;
                case 3:
                    moveDown();
                    break;
                case 4:
                    moveLeft();
                    break;
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println(Thread.currentThread().getName() + "死亡" + this);
    }

    public UsTank getEnemyTank() {
        return enemyTank;
    }

    public void setEnemyTank(UsTank enemyTank) {
        this.enemyTank = enemyTank;
    }
}
